<template>
  <div class="heritageRoad">
    <!-- header -->
    <Head />
    <Banner />
    <Nav />
    <!-- /header -->

    <div class="main">
      <div class="middle">
        <!-- 导航栏 -->
        <SideBar></SideBar>
        <!-- 导航栏 -->
        <!-- 工作室概况 -->
        <div class="block">
          <!-- 标题 -->
          <div class="title">
            <h3>传承之路</h3>
          </div>
          <!-- 内容 -->
          <div class="content">
            <div
              class="articl"
              v-for="(item,index) in cczl"
              :key="item.id"
              @click="goHeritageRoad(item.id)"
            >
              <!-- 左侧照片 -->
              <div class="pic">
                <img :src="item.zpurl" alt />
              </div>

              <!-- 右侧简介 -->
              <div class="disc">
                <p>
                  <b>姓名：</b>
                  {{item.name}}
                </p>
                <p>
                  <b>门诊时间：</b>
                  {{item.mzsj}}
                </p>
                <p>
                  <b>简介：</b>
                  {{item.ysjs}}
                </p>
              </div>
            </div>
          </div>
          <!-- 分页 -->
          <el-pagination
            @size-change="sizeChange"
            @current-change="currentChange"
            :current-page="listQuery.page"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="listQuery.limit"
            layout="total,sizes, prev, pager, next,jumper"
            :total="listQuery.total"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!-- footer -->
    <Footer></Footer>
    <!-- /footer -->
  </div>
</template>

<script>
import Head from "@/components/Head.vue";
import Banner from "@/components/Banner.vue";
import Nav from "@/components/Nav.vue";
import Footer from "@/components/Footer.vue";
import SideBar from "@/components/SideBar.vue";
export default {
  name: "HeritageRoad",
  components: {
    Head,
    Banner,
    Nav,
    Footer,
    SideBar,
  },
  data() {
    return {
      cczl: [], //传承之路
      // 页码
      listQuery: {
        total: 1,
        page: 1, //页码
        limit: 10, //每页条数
      },
    };
  },
  created() {
    this.getCczl();
  },
  methods: {
    //首页接口
    getCczl() {
      var query = {
        // id: "",
        page: this.listQuery.page,
        limit: this.listQuery.limit,
      };
      this.$axios
        .get("TCM/cczl", { params: query })
        .then((res) => {
          if (res.status == 200) {
            this.listQuery.total = res.data.count;
            this.cczl = res.data.data;
            this.cczl.forEach((item) => {
              if (item.ysjs) {
                item.ysjs = this.removeHTMLTag(item.ysjs);
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 跳转到传承之路详情页
    goHeritageRoad(id) {
      // 点击数加1
      this.addCount(id);
    },
    sizeChange(limit) {
      this.listQuery.limit = limit;
      this.currentChange(1);
    },
    currentChange(page) {
      this.listQuery.page = page;
      this.getCczl();
    },
    removeHTMLTag(str) {
      str = str.replace(/<\/?[^>]*>/g, ""); //去除HTML tag
      str = str.replace(/[ | ]*\n/g, "\n"); //去除行尾空白
      //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
      str = str.replace(/ /gi, ""); //去掉
      return str;
    },
    // 增加点击量接口
    addCount(id) {
      let queryData = {
        type: "8",
        id,
      };
      this.$axios
        .post("UpdTCM/addcount", queryData)
        .then((res) => {
          if (res.status == 200) {
            this.$router.push({ path: `/heritageroadDetail/${id}` });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
@media screen and (max-width: 1200px) {
  .heritageRoad .main {
    margin: 0 !important;
  }
}
.heritageRoad {
  background: url("../assets/image/diwen.jpg") repeat-y;
  // 通知道公告
  .main {
    margin: 0 auto;
    margin: 0 25% 0;
    height: 100%;
    background-color: #ffffff;
    overflow: hidden;
    .middle {
      height: 100%;
      padding: 0 10px 10px;
      background-color: #ffffff;
      box-sizing: border-box;
      margin-top: 20px;
      display: flex;
      justify-content: space-between;
      .block {
        flex: 1;
        margin-left: 20px;
        background-color: #ffffff;
        border: 0.5px solid #ebe4d9;
        border-top: none;
        .content {
          padding: 10px;
          .articl {
            padding: 20px 10px;
            box-sizing: border-box;
            border-bottom: 1px dotted #eaeaea;
            display: flex;
            cursor: pointer;
            .pic {
              padding-left: 40px;
              padding-right: 50px;
              height: 150px;
              width: 110px;
              overflow: hidden;
              img {
                width: 100%;
                vertical-align: middle;
              }
            }
            .disc {
              flex: 1;
              padding-right: 10px;
              p {
                font-size: 14px;
                font-weight: 500;
                letter-spacing: 1px;
                line-height: 30px;
                margin: 0;
                // 超出两行显示省略号
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 3;
                -webkit-box-orient: vertical;
                b {
                  font-size: 16px;
                  cursor: pointer;
                }
              }
            }
          }
          .articl:last-child {
            border-bottom: none;
          }
        }
        .el-pagination {
          text-align: center;
          margin-top: 20px;
          padding: 0;
          margin-bottom: 20px;
        }
      }
    }
  }
}
</style>
